package com.sansui.blog.controller;

import com.sansui.blog.pojo.SysConfig;
import com.sansui.blog.pojo.UserInfo;
import com.sansui.blog.service.SysInfoService;
import com.sansui.blog.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @name: BlogAboutController
 * @author: Sansui
 * @Software: IDEA
 * @Blog: https://www.cnblogs.com/sansui6/
 * @date: 2022-08-28 23:51
 **/
@RestController
public class BlogAboutController {
    @Autowired
    private SysInfoService sysInfoService;
    @Autowired
    private UserInfoService userInfoService;

    @GetMapping("/about")
    public ModelAndView blogAbout(ModelAndView mv, HttpSession session){

        SysConfig sysConfig = sysInfoService.getSysSetting();
        Map<String,Object> data = (Map<String, Object>) session.getAttribute("user");
        if (data != null) {
            UserInfo userInfo = userInfoService.getUserInfoByUserId(String.valueOf(data.get("uid")));
            userInfo.setPhone(null);
            userInfo.setRegisterIp(null);
            userInfo.setUpdateTime(null);
            userInfo.setCreateTime(null);
            userInfo.setUid(null);
            mv.addObject("userInfo", userInfo);
        }
        mv.setViewName("theme/"+ sysConfig.getThemeName() +"/about");
        mv.addObject("webname",sysConfig.getWebname());
        return mv;
    }
}
